﻿@{
    ViewData["Title"] = "商品列表";
}

<div class="row">
    <div class="col-md-12">
        <div class="listview list-container" ng-app="mainApp" ng-controller="mainCtrl">
            <header class="listview-header media">
                <div class="icheckbox_minimal" aria-checked="false" aria-disabled="false" style="position: relative;"><input type="checkbox" class="pull-left list-parent-check" value="" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"><ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins></div>

                <ul class="list-inline list-mass-actions pull-left">
                    <li>
                        <a data-toggle="modal" href="@Url.Action("ProductNew", "Product")" title="" class="tooltips" data-original-title="Add">
                            <i class="sa-list-add"></i>
                        </a>
                    </li>
                    <li>
                        <a href="" title="" class="tooltips" data-original-title="Refresh">
                            <i class="sa-list-refresh"></i>
                        </a>
                    </li>
                    <li class="show-on" style="display: none;">
                        <a href="" title="" class="tooltips" data-original-title="Move">
                            <i class="sa-list-move"></i>
                        </a>
                    </li>
                    <li class="show-on" style="display: none;">
                        <a href="" title="" class="tooltips" data-original-title="Delete">
                            <i class="sa-list-delete"></i>
                        </a>
                    </li>
                </ul>

                <input class="input-sm col-md-4 pull-right message-search" type="text" placeholder="Search....">

                <div class="clearfix"></div>
            </header>

            <table class="tile table table-bordered table-hover">
                <thead>
                    <tr>
                        <th width="80px">商品编号</th>
                        <th width="100px">SKU</th>
                        <th width="40%">商品名称</th>
                        <th width="20%">创建时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="x in itemlist">
                        <td>{{ x.id }}</td>
                        <td>{{ x.sku }}</td>
                        <td>{{ x.name }}</td>
                        <td>{{ x.inDate }}</td>
                        <td>{{ x.status == 0 ? "无效":"有效" }}</td>
                        <td>
                            <a href="@Url.Action("ProductEdit", "Product")?id={{ x.Id }}">编辑</a>
                            <a href="#" ng-click="delete(x.Id)">删除</a>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div class="media text-center">
                <ul class="pagination" ng-repeat="x in pages">
                    <li><a href="#" ng-click="getlist()">{{ x.index }}</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script type="text/javascript">
       var app = angular.module('mainApp', []);
       app.controller('mainCtrl', function ($scope, $http) {
           $scope.refresh = function () {
               $http.get("@Url.Action("ProductGetList", "Product")?pageindex=0&pagesize=20")
                .success(function (data) {
                    $scope.itemlist = data.Records;
                    $scope.pages = data.Paging;
                });
           }

           $scope.getlist = function (pagesize, pageindex) {
               $http.get("@Url.Action("ProductGetList", "Product")?pageindex="+pageindex+"&pagesize="+pagesize)
                    .success(function (data) {
                        $scope.itemlist = data.Records;
                        $scope.pages = data.Paging;
                });
           }

           $scope.delete = function (id) {
               if (confirm("删除是不可恢复的，你确认要删除吗？"))
               {
                   $http({
                       method: 'GET',
                       url: '@Url.Action("ProductVoid", "Product")?id='+id,
                       data: $scope.appinfo
                   })
                   .success(function (data) {
                       $scope.refresh();
                   })
                   .error(function (data) {
                       alert(data.Message)
                   });
               }
           }

           $scope.refresh();
       });
    </script>
}
